package com.aiatomic.couting.settings;

import com.aiatomic.couting.R;
import com.aiatomic.couting.SettingActivity;
import com.aiatomic.couting.TemplatesActivity;

import android.app.Fragment;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.TextView;

public class FragmentSettings extends Fragment {
	private View view;
	private SettingActivity activity;

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		view = inflater.inflate(R.layout.fragment_settings, container, false);
		activity = (SettingActivity) this.getActivity();

		TextView txtBack = (TextView) activity.findViewById(R.id.txtBack);
		txtBack.setText(R.string.main);
		txtBack.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				getActivity().onBackPressed();
			}
		});
		TextView txtNext = (TextView) activity.findViewById(R.id.txtNext);
		txtNext.setVisibility(View.INVISIBLE);

		TextView txtMiddle = (TextView) activity.findViewById(R.id.txtMiddle);
		txtMiddle.setText(R.string.bottom_setup);
		init();
		return view;
	}

	private void init() {
		view.findViewById(R.id.generalSettingsBtn).setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				FragmentGeneralSettings fr = new FragmentGeneralSettings();
				SettingActivity settingActivity = (SettingActivity) FragmentSettings.this.getActivity();
				settingActivity.addFragment(fr);
			}
		});
		view.findViewById(R.id.txt_configurations).setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent intent = new Intent(FragmentSettings.this.getActivity(), TemplatesActivity.class);
				intent.setAction(TemplatesActivity.ACTION_FROM_SETTING);
				FragmentSettings.this.startActivity(intent);
			}
		});
		view.findViewById(R.id.saveOptionsBtn).setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				FragmentSettingStore fr = new FragmentSettingStore();
				SettingActivity settingActivity = (SettingActivity) FragmentSettings.this.getActivity();
				settingActivity.addFragment(fr);
			}
		});
	}

}
